﻿using Ledict.ConditionExtract.Model;
using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
    public class SYS_QuoteLawConditionDAL
    {
        private string DbName;

        public SYS_QuoteLawConditionDAL()
        {
            DbName = "JudgeDoc";
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public bool AddSYS_QuoteLawCondition(SYS_QuoteLawCondition Model)
        {
            string strSql = string.Format(
                @"INSERT INTO [dbo].[SYS_QuoteLawCondition] (
                        QLC_ID,
	                    QLC_CaseType,
	                    QLC_Name,
	                    QLC_Content,
	                    QLC_Explain,
	                    QLC_CaseCauseId
                    )
                    VALUES
	                    ('{0}', '{1}', '{2}', '{3}','{4}','{5}')", 
                Model.QLC_ID, Model.QLC_CaseType, Model.QLC_Name, Model.QLC_Content, Model.QLC_Explain,Model.QLC_CaseCauseId);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            return Convert.ToInt32(oBase.ExecuteNonQuery(oCmd))>0?true:false; 
        }

        /// <summary>
        /// 修改一条数据
        /// </summary>
        public bool UpdateSys_QuoteLawCondition(SYS_QuoteLawCondition Model)
        {
            string strSql = string.Format(
                    @"update SYS_QuoteLawCondition set QLC_Name='{0}',QLC_Content='{1}',QLC_Explain='{2}' where QLC_ID='{3}'",
                    Model.QLC_Name, Model.QLC_Content, Model.QLC_Explain, Model.QLC_ID);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string QLC_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SYS_QuoteLawCondition where QLC_ID=@QLC_ID ");
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            oBase.AddInParameter(oCmd, "@QLC_ID", DbType.String, QLC_ID);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }
    }
}
